/* Class18 - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import java.awt.Font;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Class18 {
	public byte[] buffer;
	public long readOffset;
	public static int[] anIntArray338;
	public long baseFileOffset;
	public long aLong340 = -1L;
	public static int anInt341;
	public long aLong342;
	public int anInt343;
	public static int anInt344 = 1;
	public static int[] anIntArray345;
	public static Class57 aClass57_346;
	public long aLong347;
	public static JString aClass3_348 = Class39_Sub5_Sub9.createJString(119, "backright1");
	public long virtualFileOffset = -1L;
	public static Class39_Sub5_Sub10_Sub4 aClass39_Sub5_Sub10_Sub4_350;
	public static Font aFont351;
	public LocalFile file;
	public int anInt353 = 0;
	public byte[] aByteArray354;

	public void seek(int i, long l) {
		if (l >= 0L)
			baseFileOffset = l;
	}

	public static JString[] method225(byte i, JString[] class3s) {
		JString[] class3s_0_ = new JString[5];
		for (int i_1_ = 0; i_1_ < 5; i_1_++) {
			class3s_0_[i_1_] = Class39_Sub5_Sub11.method708((new JString[] { Class57.method1007((byte) 71, i_1_), Class31.aClass3_556 }), 14569);
			if (class3s != null && class3s[i_1_] != null)
				class3s_0_[i_1_] = Class39_Sub5_Sub11.method708((new JString[] { class3s_0_[i_1_], class3s[i_1_] }), 14569);
		}
		return class3s_0_;
	}

	public void method226(byte i) throws IOException {
		method231();
		file.close();
	}

	public void read(byte[] dest, int readLength, int i_2_, int destOffset) throws IOException {
		try {
			if (destOffset + readLength > dest.length)
				throw new ArrayIndexOutOfBoundsException(-dest.length + readLength + destOffset);
			if (aLong340 != -1L && baseFileOffset >= aLong340 && baseFileOffset + (long) readLength <= (long) anInt353 + aLong340) {
				ArrayOperations.copy(aByteArray354, (int) (baseFileOffset - aLong340), dest, destOffset, readLength);
				baseFileOffset += (long) readLength;
				return;
			}
			long l = baseFileOffset;
			int i_4_ = destOffset;
			int i_5_ = readLength;
			if (baseFileOffset >= virtualFileOffset && baseFileOffset < (long) anInt343 + virtualFileOffset) {
				int len = (int) (-baseFileOffset + (virtualFileOffset + (long) anInt343));
				if (readLength < len)
					len = readLength;
				readLength -= len;
				ArrayOperations.copy(buffer, (int) (baseFileOffset + -virtualFileOffset), dest, destOffset, len);
				baseFileOffset += (long) len;
				destOffset += len;
			}
			if (buffer.length >= readLength) {
				if (readLength > 0) {
					fillBuffer(-21473);
					int i_7_ = readLength;
					if (anInt343 < i_7_)
						i_7_ = anInt343;
					readLength -= i_7_;
					ArrayOperations.copy(buffer, 0, dest, destOffset, i_7_);
					destOffset += i_7_;
					baseFileOffset += (long) i_7_;
				}
			} else {
				file.seek(baseFileOffset);
				readOffset = baseFileOffset;
				while (readLength > 0) {
					int i_8_ = file.read(dest, readLength, destOffset);
					if (i_8_ == -1)
						break;
					readLength -= i_8_;
					destOffset += i_8_;
					readOffset += (long) i_8_;
					baseFileOffset += (long) i_8_;
				}
			}
			if (aLong340 != -1L) {
				if (aLong340 > baseFileOffset && readLength > 0) {
					int i_9_ = destOffset + (int) (-baseFileOffset + aLong340);
					if (readLength + destOffset < i_9_)
						i_9_ = readLength + destOffset;
					while (destOffset < i_9_) {
						readLength--;
						dest[destOffset++] = (byte) 0;
						baseFileOffset++;
					}
				}
				long l_10_ = -1L;
				if (l >= aLong340 - -(long) anInt353 || aLong340 - -(long) anInt353 > l + (long) i_5_) {
					if (aLong340 < (long) i_5_ + l && (long) i_5_ + l <= (long) anInt353 + aLong340)
						l_10_ = l + (long) i_5_;
				} else
					l_10_ = (long) anInt353 + aLong340;
				long l_11_ = -1L;
				if (aLong340 >= l && aLong340 < (long) i_5_ + l)
					l_11_ = aLong340;
				else if (l >= aLong340 && aLong340 - -(long) anInt353 > l)
					l_11_ = l;
				if (l_11_ > -1L && l_11_ < l_10_) {
					int i_12_ = (int) (-l_11_ + l_10_);
					ArrayOperations.copy(aByteArray354, (int) (-aLong340 + l_11_), dest, i_4_ + (int) (l_11_ + -l), i_12_);
					if (baseFileOffset < l_10_) {
						readLength -= l_10_ + -baseFileOffset;
						baseFileOffset = l_10_;
					}
				}
			}
		} catch (IOException ioexception) {
			readOffset = -1L;
			throw ioexception;
		}
		if (readLength > 0)
			throw new EOFException();
	}

	public long length() {
		return aLong347;
	}

	public void fillBuffer(int i) throws IOException {
		anInt343 = 0;
		if (baseFileOffset != readOffset) {
			file.seek(baseFileOffset);
			readOffset = baseFileOffset;
		}
		if (i != -21473)
			buffer = null;
		virtualFileOffset = baseFileOffset;
		int i_13_;
		for (/**/; anInt343 < buffer.length; anInt343 += i_13_) {
			i_13_ = file.read(buffer, buffer.length - anInt343, anInt343);
			if (i_13_ == -1)
				break;
			readOffset += (long) i_13_;
		}
	}

	public static int method230(boolean bool, Class9 class9, Class9 class9_14_) {
		int i = 0;
		if (class9.method152(22411, Tile.aClass3_1906, Class4.aClass3_69))
			i++;
		if (class9_14_.method152(22411, Tile.aClass3_1906, Class39_Sub11.aClass3_1481))
			i++;
		if (class9_14_.method152(22411, Tile.aClass3_1906, Class23.aClass3_422))
			i++;
		if (class9_14_.method152(22411, Tile.aClass3_1906, Class39_Sub5_Sub4_Sub5.aClass3_2339))
			i++;
		if (class9_14_.method152(22411, Tile.aClass3_1906, RSSocket.aClass3_310))
			i++;
		return i;
	}
	

	public void method231() throws IOException {
		if (aLong340 != -1L) {
			if (aLong340 != readOffset) {
				file.seek(aLong340);
				readOffset = aLong340;
			}
			long l = -1L;
			file.write(anInt353, 0, aByteArray354);
			if (virtualFileOffset > aLong340 || aLong340 >= (long) anInt343 + virtualFileOffset) {
				if (virtualFileOffset >= aLong340 && virtualFileOffset < aLong340 - -(long) anInt353)
					l = virtualFileOffset;
			} else
				l = aLong340;
			readOffset += (long) anInt353;
			long l_16_ = -1L;
			if (readOffset > aLong342)
				aLong342 = readOffset;
			if (virtualFileOffset >= aLong340 - -(long) anInt353 || virtualFileOffset - -(long) anInt343 < (long) anInt353 + aLong340) {
				if (virtualFileOffset - -(long) anInt343 > aLong340 && ((long) anInt343 + virtualFileOffset <= (long) anInt353 + aLong340))
					l_16_ = (long) anInt343 + virtualFileOffset;
			} else
				l_16_ = aLong340 + (long) anInt353;
			if (l > -1L && l < l_16_) {
				int i_17_ = (int) (l_16_ + -l);
				ArrayOperations.copy(aByteArray354, (int) (-aLong340 + l), buffer, (int) (l - virtualFileOffset), i_17_);
			}
			anInt353 = 0;
			aLong340 = -1L;
		}
	}

	public static void method232(int i) {
		anIntArray338 = null;
		anIntArray345 = null;
		aFont351 = null;
		aClass39_Sub5_Sub10_Sub4_350 = null;
		aClass57_346 = null;
		aClass3_348 = null;
	}
	

	public static void method233(int i, int i_18_, PacketStream class39_sub6_sub1) {
		if (i == -14) {
			for (;;) {
				Class39_Sub7 class39_sub7 = (Class39_Sub7) Class15.aClass49_283.method969(false);
				if (class39_sub7 == null)
					break;
				boolean bool = false;
				for (int i_19_ = 0; class39_sub7.anInt1382 > i_19_; i_19_++) {
					if (class39_sub7.aClass56Array1377[i_19_] != null) {
						if (class39_sub7.aClass56Array1377[i_19_].state == 2)
							class39_sub7.anIntArray1376[i_19_] = -5;
						if (class39_sub7.aClass56Array1377[i_19_].state == 0)
							bool = true;
					}
					if (class39_sub7.aClass56Array1383[i_19_] != null) {
						if (class39_sub7.aClass56Array1383[i_19_].state == 2)
							class39_sub7.anIntArray1376[i_19_] = -6;
						if (class39_sub7.aClass56Array1383[i_19_].state == 0)
							bool = true;
					}
				}
				if (bool)
					break;
				class39_sub6_sub1.writePacket(i_18_);
				class39_sub6_sub1.writeByte((byte) -28, 0);
				int i_20_ = class39_sub6_sub1.currentOffset;
				class39_sub6_sub1.writeInt(class39_sub7.anInt1372);
				for (int i_21_ = 0; i_21_ < class39_sub7.anInt1382; i_21_++) {
					if (class39_sub7.anIntArray1376[i_21_] != 0)
						class39_sub6_sub1.writeByte((byte) -28, (class39_sub7.anIntArray1376[i_21_]));
					else {
						try {
							int i_22_ = class39_sub7.anIntArray1378[i_21_];
							if (i_22_ != 0) {
								if (i_22_ == 1) {
									Field field = ((Field) (class39_sub7.aClass56Array1377[i_21_].resource));
									field.setInt(null, (class39_sub7.anIntArray1379[i_21_]));
									class39_sub6_sub1.writeByte((byte) -28, 0);
								} else if (i_22_ == 2) {
									Field field = ((Field) (class39_sub7.aClass56Array1377[i_21_].resource));
									int i_23_ = field.getModifiers();
									class39_sub6_sub1.writeByte((byte) -28, 0);
									class39_sub6_sub1.writeInt(i_23_);
								}
							} else {
								Field field = (Field) (class39_sub7.aClass56Array1377[i_21_].resource);
								int i_24_ = field.getInt(null);
								class39_sub6_sub1.writeByte((byte) -28, 0);
								class39_sub6_sub1.writeInt(i_24_);
							}
							if (i_22_ == 3) {
								Method method = (Method) (class39_sub7.aClass56Array1383[i_21_].resource);
								byte[][] is = (class39_sub7.aByteArrayArrayArray1381[i_21_]);
								Object[] objects = new Object[is.length];
								for (int i_25_ = 0; i_25_ < is.length; i_25_++) {
									ObjectInputStream objectinputstream = (new ObjectInputStream(new ByteArrayInputStream(is[i_25_])));
									objects[i_25_] = objectinputstream.readObject();
								}
								Object object = method.invoke(null, objects);
								if (object == null)
									class39_sub6_sub1.writeByte((byte) -28, 0);
								else if (!(object instanceof Number)) {
									if (!(object instanceof JString))
										class39_sub6_sub1.writeByte((byte) -28, 4);
									else {
										class39_sub6_sub1.writeByte((byte) -28, 2);
										class39_sub6_sub1.writeString((byte) 72, ((JString) object));
									}
								} else {
									class39_sub6_sub1.writeByte((byte) -28, 1);
									class39_sub6_sub1.writeLong(true, ((Number) object).longValue());
								}
							} else if (i_22_ == 4) {
								Method method = (Method) (class39_sub7.aClass56Array1383[i_21_].resource);
								int i_26_ = method.getModifiers();
								class39_sub6_sub1.writeByte((byte) -28, 0);
								class39_sub6_sub1.writeInt(i_26_);
							}
						} catch (ClassNotFoundException classnotfoundexception) {
							class39_sub6_sub1.writeByte((byte) -28, -10);
						} catch (java.io.InvalidClassException invalidclassexception) {
							class39_sub6_sub1.writeByte((byte) -28, -11);
						} catch (java.io.StreamCorruptedException streamcorruptedexception) {
							class39_sub6_sub1.writeByte((byte) -28, -12);
						} catch (java.io.OptionalDataException optionaldataexception) {
							class39_sub6_sub1.writeByte((byte) -28, -13);
						} catch (IllegalAccessException illegalaccessexception) {
							class39_sub6_sub1.writeByte((byte) -28, -14);
						} catch (IllegalArgumentException illegalargumentexception) {
							class39_sub6_sub1.writeByte((byte) -28, -15);
						} catch (java.lang.reflect.InvocationTargetException invocationtargetexception) {
							class39_sub6_sub1.writeByte((byte) -28, -16);
						} catch (SecurityException securityexception) {
							class39_sub6_sub1.writeByte((byte) -28, -17);
						} catch (IOException ioexception) {
							class39_sub6_sub1.writeByte((byte) -28, -18);
						} catch (NullPointerException nullpointerexception) {
							class39_sub6_sub1.writeByte((byte) -28, -19);
						} catch (Exception exception) {
							class39_sub6_sub1.writeByte((byte) -28, -20);
						} catch (Throwable throwable) {
							class39_sub6_sub1.writeByte((byte) -28, -21);
						}
					}
				}
				class39_sub6_sub1.method791(i + 135, i_20_);
				class39_sub6_sub1.method816(-i_20_ + class39_sub6_sub1.currentOffset, -12139);
				class39_sub7.unlink();
			}
		}
	}

	public void write(int writeLength, int srcOffset, int i_28_, byte[] src) throws IOException {
		try {
			if ((long) writeLength + baseFileOffset > aLong347)
				aLong347 = (long) writeLength + baseFileOffset;
			if (aLong340 != -1L && (aLong340 > baseFileOffset || aLong340 + (long) anInt353 < baseFileOffset))
				method231();
			if (aLong340 != -1L && ((long) aByteArray354.length + aLong340 < baseFileOffset - -(long) writeLength)) {
				int i_29_ = (int) ((long) aByteArray354.length - -aLong340 - baseFileOffset);
				writeLength -= i_29_;
				ArrayOperations.copy(src, srcOffset, aByteArray354, (int) (baseFileOffset + -aLong340), i_29_);
				baseFileOffset += (long) i_29_;
				anInt353 = aByteArray354.length;
				method231();
				srcOffset += i_29_;
			}
			if (writeLength > aByteArray354.length) {
				if (readOffset != baseFileOffset) {
					file.seek(baseFileOffset);
					readOffset = baseFileOffset;
				}
				file.write(writeLength, srcOffset, src);
				long l = -1L;
				if (virtualFileOffset >= baseFileOffset + (long) writeLength || (long) anInt343 + virtualFileOffset < baseFileOffset + (long) writeLength) {
					if (baseFileOffset < virtualFileOffset - -(long) anInt343 && virtualFileOffset - -(long) anInt343 <= (long) writeLength + baseFileOffset)
						l = (long) anInt343 + virtualFileOffset;
				} else
					l = (long) writeLength + baseFileOffset;
				readOffset += (long) writeLength;
				if (aLong342 < readOffset)
					aLong342 = readOffset;
				long l_30_ = -1L;
				if (baseFileOffset < virtualFileOffset || baseFileOffset >= virtualFileOffset + (long) anInt343) {
					if (virtualFileOffset >= baseFileOffset && virtualFileOffset < (long) writeLength + baseFileOffset)
						l_30_ = virtualFileOffset;
				} else
					l_30_ = baseFileOffset;
				if (l_30_ > -1L && l_30_ < l) {
					int i_31_ = (int) (l - l_30_);
					ArrayOperations.copy(src, (int) ((long) srcOffset + (l_30_ - baseFileOffset)), buffer, (int) (-virtualFileOffset + l_30_), i_31_);
				}
				baseFileOffset += (long) writeLength;
			} else if (writeLength > 0) {
				if (aLong340 == -1L)
					aLong340 = baseFileOffset;
				ArrayOperations.copy(src, srcOffset, aByteArray354, (int) (-aLong340 + baseFileOffset), writeLength);
				baseFileOffset += (long) writeLength;
				if ((long) anInt353 < -aLong340 + baseFileOffset)
					anInt353 = (int) (baseFileOffset - aLong340);
			}
		} catch (IOException ioexception) {
			readOffset = -1L;
			throw ioexception;
		}
	}

	public static void method235(byte i) {
		if (Class2.anInt53 != 0) {
			int i_32_ = 0;
			if (Class39_Sub7.anInt1380 != 0)
				i_32_ = 1;
			for (int i_33_ = 0; i_33_ < 100; i_33_++) {
				if (Class2.aClass3Array52[i_33_] != null) {
					int i_34_ = client.anIntArray1268[i_33_];
					JString class3 = Class39_Sub11.aClass3Array1462[i_33_];
					if (class3 != null && class3.startsWith(Class37.aClass3_661))
						class3 = class3.substring(5);
					if (class3 != null && class3.startsWith(Class53.aClass3_959))
						class3 = class3.substring(5);
					if ((i_34_ == 3 || i_34_ == 7) && (i_34_ == 7 || Class11.privateChatOptions == 0 || (Class11.privateChatOptions == 1 && JString.method60(21469, class3)))) {
						int i_35_ = 329 - i_32_ * 13;
						if (ISAAC.anInt1091 > 4 && Class33.anInt599 - 4 > i_35_ - 10 && Class33.anInt599 - 4 <= i_35_ + 3) {
							int i_36_ = (Tile.aClass39_Sub5_Sub10_Sub1_1903.method637(Class39_Sub5_Sub11.method708((new JString[] { Class39_Sub5_Sub16.aClass3_1991, OnDemandFetcher.aClass3_1204, class3, Class2.aClass3Array52[i_33_] }), 14569))) + 25;
							if (i_36_ > 450)
								i_36_ = 450;
							if (ISAAC.anInt1091 < 4 + i_36_) {
								Class26.anInt482++;
								Class39_Sub5_Sub6.anInt1759++;
								if (CacheIO.anInt97 >= 1) {
									Class4.anInt60++;
									JString.method55(0, Class34.aClass3_608, 0, (Class39_Sub5_Sub11.method708((new JString[] { (Renderable.aClass3_1728), class3 }), 14569)), (byte) -128, 0, 2009);
								}
								JString.method55(0, Class39_Sub5_Sub1.aClass3_1683, 0, (Class39_Sub5_Sub11.method708((new JString[] { (Renderable.aClass3_1728), class3 }), 14569)), (byte) -28, 0, 2021);
								JString.method55(0, Class44.aClass3_835, 0, (Class39_Sub5_Sub11.method708((new JString[] { (Renderable.aClass3_1728), class3 }), 14569)), (byte) -114, 0, 2031);
							}
						}
						if (++i_32_ >= 5)
							break;
					}
					if ((i_34_ == 5 || i_34_ == 6) && Class11.privateChatOptions < 2 && ++i_32_ >= 5)
						break;
				}
			}
		}
	}

	public static int method236(boolean bool) {
		return 19;
	}

	public Class18(LocalFile class8, int i, int i_37_) throws IOException {
		file = class8;
		aLong347 = aLong342 = class8.length();
		baseFileOffset = 0L;
		buffer = new byte[i];
		aByteArray354 = new byte[i_37_];
	}

	static {
		anInt341 = 0;
	}
}
